"""
class Parent1:
    xxx = 333 # 类属性
    def run(self):
        print("我是父类的方法")


class Sub1(Parent1):
    # xxx = 222 # 类属性
    pass

s1 = Sub1()
s1.run()

print(s1.xxx)
# 优先使用它自己的，自己没有，再去找爸爸
"""
"""
class People:
    school = "不造啊"
    def __init__(self,name,age,sex):
        self.name = name
        self.age = age
        self.sex = sex

class Student(People):
    def play(self):
        print("%s play football"%self.name)

class Teacher(People):
    def course(self):
        print("%s course"%self.name)


s1 = Student("张三",'23',"男")
s1.play()
# print(s1.school)
s2 = Teacher("张六",'46',"男")
s2.course()
"""
# 不算继承关系，引用其他类的初始化构造方法
"""
class People:
    school = '不造啊'
    def __init__(self,name,age,sex):
        self.name = name
        self.age = age
        self.sex = sex
class Student():
    def __init__(self,name,age,sex,score = 0):
        People.__init__(self,name,age,sex)
        self.score = score
    def play(self):
        print('%s play football' % self.name)
class Teacher():
    def __init__(self,name,age,sex,hobby):
        People.__init__(self,name,age,sex)
        self.hobby = hobby
    def course(self):
        print("%s course"%self.name)

if __name__ == '__main__':
    stu1 = Student("小龙",30,'male',100)
    print(stu1.__dict__)
    tea1 = Teacher("小白",18,'man','篮球')
    print(tea1.__dict__)
"""
# super() 引用父类的属性
# 所有的类，都是继承object类的
"""
class People(object):
    school = '不造呀'
    def __init__(self,name,age,sex):
        self.name = name
        self.age = age
        self.sex = sex
class Student(People,object):
    def __init__(self,name,age,sex,score=0):
        super(Student,self).__init__(name,age,sex)
        self.score = score
    def play(self):
        print("%s play football"% self.name)

class Teacher(People,object):
    def __init__(self,name,age,sex,hobby):
        super().__init__(name,age,sex)
        self.hobby = hobby
    def course(self):
        print("%s course"%self.name)
if __name__ == '__main__':
    stu1 = Student("张三",30,'male',100)
    print(stu1.__dict__)
"""
# 单继承背景下的属性查找顺序
"""
class Foo:
    xxx = 444
    
class Bar1(Foo):
    # xxx = 333
    pass
class Bar2(Bar1):
    # xxx = 222
    pass
if __name__ == '__main__':
    
    #继承关系：
    #父和子都有这个属性的话，优先使用子的
    
    b1 = Bar2()
    print(b1.xxx)
"""
"""
class Foo:
    def f1(self):
        print("foo.f1")
    def f2(self):
        print("Foo.f2")
        self.f1()
class Bar(Foo):
    pass
    # def f1(self):
    #     print("Bar.f1")
if __name__ == '__main__':
    #如果子类里有和父类重名的方法，优先用子类的   
    obj = Bar()
    obj.f1()
"""
# 在多继承背景下的属性查找
"""
多继承的时候，广度优先查找,从左往右一个分支一个分支的查找,在最后一个分支才去查找顶级类
"""
"""
class B1():
    pass
class G1():
    x = 55
    pass
class G(object):
    x = 'G'
    pass
# 第三层
class E(G):
    # x = 'E'
    pass
class F(G1):
    #x='F'
    pass
# 第二层
class B(E):
    #x= "B"
    pass
class C(F):
    #x='C'
    pass
class D(B1):
    #x='D'
    pass
# 第一层
class A(B,C,D):
    # x = 'A'
    pass
if __name__ == '__main__':
    obj = A()
    # print(obj.x)
    print(A.mro())
"""


